/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.iprojectmanager.views;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import com.iprojectmanager.managers.*;
import com.iprojectmanager.entities.*;
//import java.util.Enumeration;

/**
 *
 * @author Enrique
 */
public class VistaEnviarAvance extends Vista{
    
    
    public void mainView(PrintWriter out,IntegranteProyecto user)
    throws ServletException, IOException
    {

        out.println(Utilities.getDocType());
        out.println("<HTML>" + Utilities.getHead("Enviar Avance"));
        out.println("<div id=\"container\">");
        out.println(Utilities.getIntro("Integrante del Proyecto: " + user.getProyecto().getNombre(),user));
        String content = "<div id=\"pageContent\">"+
               "<div id=\"selection1\">"+"</div>"+
               this.getFormActivities(user) +
               Utilities.getFooter() + "</div>";
        out.println(content);
        out.println(Utilities.getMenu());
        out.println("</div> <!-- fin container --> </BODY></HTML>");
    }
    
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        PrintWriter out = response.getWriter();
        HttpSession user = request.getSession();
        IntegranteProyecto enviador = (IntegranteProyecto)user.getAttribute("user");
        response.setContentType("text/html");
        mainView(out,enviador);
        request.getSession().setAttribute("actividad", new String("Hola batiz"));
    }
    
    @Override
    public String getServletInfo(){
        return "Vista Enviar Avance";
    }
    
    public String getFormActivities(IntegranteProyecto user)
    {
        //ActivitiesManager manager = new ActivitiesManager();
        Proyecto proyecto = user.getProyecto();
        String actividades = "";
        for(Actividad lista : proyecto.getActividades()){
            if(lista.getResponsable() != null && lista.getResponsable().equals(user))
                actividades += "<option value=\""+lista.getId()+
                        "\">" + lista.getNombre() + "</option>";
        }
        return "<h3><span>Enviar Avance</span></h3>"+
                "<p class=\"p1\"><span>"+
                "<form action=\"VistaArchivo\" method=\"GET\">"+
                    "<label>ACTIVIDADES:</label>"+
                        "<select name=\"actividades\" size=1>"+
                            actividades +
                        "</select>" +
                        "<br></br>"+
                    "<button type=\"submit\">Aceptar</button>"+
                "</form>"+
                "</span></p>";        
    }
}

